﻿/*
   View for CustomerOrdersForm.
*/
if exists(select * from dbo.sysobjects where 
   id = object_id(N'[dbo].[vw_CustomerOrdersProducts]') and
   OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[vw_CustomerOrdersProducts]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[vw_CustomerOrdersProducts]
AS
SELECT dbo.Customer.ID AS CustomerId, dbo.[Order].ID AS OrderId, 
       dbo.Product.ID AS ProductId, dbo.Product.Name, 
       dbo.OrderDetail.UnitPrice, 
       dbo.OrderDetail.Quantity, dbo.OrderDetail.Discount, 
       dbo.OrderDetail.UnitPrice * dbo.OrderDetail.Quantity *
           (1-[Discount]) AS ExtendedPrice
FROM   dbo.Customer INNER JOIN
       dbo.[Order] ON dbo.Customer.ID = dbo.[Order].CustomerId INNER JOIN
       dbo.OrderDetail ON dbo.[Order].ID = dbo.OrderDetail.OrderID INNER JOIN
       dbo.Product ON dbo.OrderDetail.ProductID = dbo.Product.ID
GO